######################################################
#Figure D7: Spending Demand by Risk Type Over Time
#Author: Raluca L. Pahontu
#####################################################

data <- read.dta13("rdata_trends.dta")
ggplot(data, aes(as.factor(year), spending_mean, group=as.factor(rho), color=as.factor(rho))) +
  geom_point(size = 2) +
  geom_line(stat = "smooth", method = "lm", span = 1,  size = 2, alpha = 0.4) + 
  xlab("Year") + ylab("Mean Social Spending") +
  scale_color_manual(values=c("black","grey40","grey70"), name="Work Type", 
                     labels=c(expression(paste(rho,3)), expression(paste(rho,2)), expression(paste(rho,1)))) + 
  theme_bw() +
  theme(legend.key=element_blank(),
        legend.text=element_text(color="black", size=10),
        panel.background = element_blank(),
        panel.border = element_blank(),
        panel.grid.major = element_line(linetype = "dotted", size=.4, colour="grey90"),
        panel.grid.minor = element_line(linetype = "dotted", size=.4, colour="grey90"),
        axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0)),
        axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0)),
        axis.ticks.length=unit(0.3,"cm"),
        axis.text = element_text(colour ="black"))  +
  coord_cartesian(ylim=c(.2, .8)) +
  geom_segment(x=0.4, xend=0.4, y=0.2, yend=0.8, col="black") +
  geom_segment(x=1, xend=13, y=0.17, yend=.17, col="black") 
ggsave("figure_d7.pdf")




